﻿#ifndef FORMATPANEL_H
#define FORMATPANEL_H

#include "formatpanelglobal.h"
#include "iformatpanel.h"
#include <QWidget>
#include <QListWidget>
#include <QPushButton>
#include <QLabel>
#include <QMap>

class FORMATPANEL_EXPORT FormatPanel : public QWidget, public IFormatPanel
{
	Q_OBJECT 

public:
	explicit FormatPanel(QWidget* parent = nullptr);

	QWidget* widget() override { return this; }
	void addStyle(const FormatStyle& style) override;
	void updateStyle(const QString& name, const FormatStyle& style) override;
	void removeStyle(const QString& name) override;
	void clearStyles() override;

	void setCurrentStyle(const QString& name) override;
	QString currentStyle() const override;

	void syncRibbonState
	(
		const QString& fontFamily,
		int fontSize,
		bool bold,
		bool italic,
		bool underline
	) override;

	FormatStyle getStyle(const QString& name) const override; 

signals:  
	void styleSelected(const QString& name);
	void clearFormatClicked();
	void resetDefaultsClicked();

private slots:
	void onStyleSelected(QListWidgetItem* item);
	void onClearFormatClicked();
	void onResetDefaultsClicked();

private:
	void initUI();
	void initDefaultStyles();
	void updateStylePreview(FormatStyle& style);
	void updateCurrentStylePreview();
	QIcon createStylePreviewIcon(const FormatStyle& style);

	QListWidget* m_styleList;
	QLabel* m_currentStyleLabel;
	QLabel* m_fontLabel;
	QLabel* m_sizeLabel;
	QLabel* m_formatLabel;
	QPushButton* m_clearFormatBtn;
	QPushButton* m_resetDefaultsBtn;

	QMap<QString, FormatStyle> m_styles;
	FormatStyle m_currentRibbonState;
};

#endif // FORMATPANEL_H